<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path;
    %>
    <meta charset="utf-8"/>
    <title>Title</title>
    <!-- Bootstrap 核心 CSS 文件https://git.oschina.net/cbyh1313/photoShareProject1.git-->
    <link href="../resources/package/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- 在bootstrap.min.js 之前引入 -->
    <script src="../resources/package/jquery/jquery-3.1.1.min.js"></script>
    <!-- Bootstrap 核心 JavaScript 文件 -->
    <script src="../resources/package/bootstrap/js/bootstrap.min.js"></script>
    <script>
        function ajaxRequest() {
            $.ajax({
                type: "POST",
                url: "<%=basePath%>/user/list",
                data: {
//                "idItem":string
                },
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                dataType: "json",
                success: function (data) {
                    console.log(data)
                    addNode(data)
                },
                error: function (xhr) {
                    alert(xhr.responseText)
                }
            });
        }
        function addNode(data) {
            $(".table").find("tbody").append(" <tr>" +
                "<td>" + data.account + "</td>" +
                "<td>" + data.createTime + "</td>" +
                "<td>" + data.username + "</td>" +
                "</tr>")
        }

    </script>
</head>
<body>
<div class="container">
    <table class="table table-striped">
        <caption>用户列表</caption>
        <thead>
        <tr>
            <th>账号</th>
            <th>创建时间</th>
            <th>名字</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="u" items="${userList}">
            <tr>
                <td>${u.account}</td>
                <td>${u.createTime}</td>
                <td>${u.username}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <button class="btn btn-primary" onclick="ajaxRequest()">刷新</button>
    <div id="myDiv"></div>
</div>
</body>
</html>
